import {createSlice, PayloadAction} from "@reduxjs/toolkit";
import {produce} from "immer";

export type PageInfoType = {
    title: string,
    desc?: string,
    js?: string,
    css?: string
}

const INIT_STATE: PageInfoType = {
    title: '',
    desc: '',
    js: "",
    css: ''
}

const pageInfoReducer = createSlice({
    name: 'pageInfo',
    initialState: INIT_STATE,
    reducers: {
        resetPageInfo: (state: PageInfoType, action: PayloadAction<PageInfoType>) => {
            return action.payload
        },
        changePageInfoTitle: produce((draft: PageInfoType, action: PayloadAction<string>) => {
            draft.title = action.payload
        })
    }
})
export default pageInfoReducer.reducer
export const {resetPageInfo, changePageInfoTitle} = pageInfoReducer.actions
